﻿using System;
using StockAccessors;
using StockModel;

namespace Plugins.Historical
{
	public class FakeOrderExecutor : IOrderExecutor
	{
		#region Properties

		public Quotation NextQuotation { get; set; }

		#endregion

		#region Public Methods

		public bool IsSimulationEnabled
		{
			get
			{
				throw new NotImplementedException("Simulation mode has no sense on historical mode");
			}
			set
			{
				throw new NotImplementedException("Simulation mode has no sense on historical mode");
			}
		}

		public OperationExecutionResult ExecuteMarketOrder(string symbol, int volume, bool buySell)
		{
			if (buySell)
			{
				return new OperationExecutionResult(this.NextQuotation.Buyers[0].Value > 0 ? this.NextQuotation.Buyers[0].Value : this.NextQuotation.Value, this.NextQuotation.Date);
			}
			else
			{
				return new OperationExecutionResult(this.NextQuotation.Sellers[0].Value > 0 ? this.NextQuotation.Sellers[0].Value : this.NextQuotation.Value, this.NextQuotation.Date);
			}
		}

		public OperationExecutionResult ExecuteMarketOrderInOpeningBid(string symbol, int volume, bool buySell)
		{
			throw new NotImplementedException();
		}

		public void ExecuteLimitedOrder(string symbol, int volume, bool buySell, decimal value)
		{
			throw new NotImplementedException("Limited orders has no sense on historical mode as there is no way of knowing if they'll execute or not");
		}

		#endregion
	}
}
